package com.star.star.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.star.star.R;
import com.star.star.bean.buylistBean;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2018/9/12 0012.
 */

public class BuyListFragment extends Fragment {
    public String mTitle;
    private buylistdapter adapte;
    private RecyclerView mRecylerView;
    private List<buylistBean> list = new ArrayList<>();

    public static BuyListFragment getInstance(String title) {
        BuyListFragment sf = new BuyListFragment();
        sf.mTitle = title;
        return sf;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.activity_aid_list, container, false);
        mRecylerView = view.findViewById(R.id.rv_recycleview);
        RelativeLayout title_bar = view.findViewById(R.id.title_bar);
        title_bar.setVisibility(View.GONE);
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        mRecylerView.setLayoutManager(manager);
        mRecylerView.setHasFixedSize(true);//每个 高度一样
        mRecylerView.setNestedScrollingEnabled(false);
        list.add(new buylistBean("星期一", "品牌活动", "上海 | 活动"));
        list.add(new buylistBean("星期二", "时尚魅力盛典", "上海 | 活动"));
        list.add(new buylistBean("星期三", "魅力都市生活", "北京 | 活动"));
        list.add(new buylistBean("星期四", "开业电流", "西安 | 活动"));
        list.add(new buylistBean("星期五", "开业典礼活动", "上海 | 活动"));
        list.add(new buylistBean("星期六", "品牌活动", "上海 | 活动"));
        adapte = new buylistdapter();
        mRecylerView.setAdapter(adapte);
        adapte.notifyDataSetChanged();
        return view;

    }


    public class buylistdapter extends RecyclerView.Adapter {
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.buylist_adapter_item, parent, false);
            return new MYholder(view);
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
            MYholder holder1 = (MYholder) holder;
            holder1.setdata(position);
        }

        @Override
        public int getItemCount() {
            return list.size();
        }

        private class MYholder extends RecyclerView.ViewHolder {

            private final TextView tv_day, tv_day_name, tv_day_there;

            public MYholder(View view) {
                super(view);
                tv_day = view.findViewById(R.id.tv_day);
                tv_day_name = view.findViewById(R.id.tv_day_name);
                tv_day_there = view.findViewById(R.id.tv_day_there);
            }

            public void setdata(final int position) {
                tv_day.setText(list.get(position).getDay());
                tv_day_name.setText(list.get(position).getName());
                tv_day_there.setText(list.get(position).getAddress());

            }
        }
    }

}
